package us.icitap.commandcenter.ui.dispatcher;

import java.util.List;

import us.icitap.commandcenter.business.ejb.persistence.Call;
import us.icitap.commandcenter.ui.custom.CustColumnGenerator;
import us.icitap.commandcenter.ui.custom.CustTable;

import com.vaadin.data.util.BeanItemContainer;

public class StartedVerificationTable extends CustTable{
	
	private final BeanItemContainer<Call> beans = new BeanItemContainer<Call>(Call.class);

	public StartedVerificationTable(boolean oneDispatcher) {
		this.setContainerDataSource(beans);

		if(!oneDispatcher){
			this.setVisibleColumns(new Object[]{"caller","recordDate", "callReason", "address", "description", "mainDispatcher", "shiftCommander"});
			this.setColumnHeaders(new String[]{"TELEFONUESI", "DT. REGJ.", "ARSYEJA E TELEFONATES", "ADRESA", "PERSHKRIMI","Z. MBULIMIT", "NJOFTUAR"});
			this.addGeneratedColumn("mainDispatcher", CustColumnGenerator.dispatcherColumnGenerator);
		}
		else{
			this.setVisibleColumns(new Object[]{"caller","recordDate", "callReason", "address", "description", "shiftCommander"});
			this.setColumnHeaders(new String[]{"TELEFONUESI", "DT. REGJ.", "ARSYEJA E TELEFONATES", "ADRESA", "PERSHKRIMI", "NJOFTUAR"});
		}
		
		this.addGeneratedColumn("callReason", CustColumnGenerator.callReasonColumnGenerator);
		
		this.setPageLength(10);
		this.setWidth("100%");
		this.setColumnWidth("callReason", 100);
		this.setColumnWidth("address", 200);
		this.setColumnWidth("description", 200);
		
		this.updateTable();
		this.setSelectable(true);   
		this.setImmediate(true);
		
		this.addStyleName("yellow");
		
		
	}
	

	public void updateTable(){
		boolean[] order = {false};
		this.sort(new Object[]{"recordDate"}, order);
		this.setCaption("Totali i telefonatave me status NE PRITJE PER VERIFIKIM: " + beans.size());
	}
	
	
	public void addCallToTable(List<Call> callList){
		beans.addAll(callList);
		this.updateTable();
	}
	public void addCallToTable(Call call){
		beans.addBean(call);
		updateTable();
	}
	
	public void removeCallFromTable(Call call){
		this.beans.removeItem(call);
		this.updateTable();
	}
	
	public void updateCall(Call call){
		beans.removeItem(call);
		beans.addBean(call);
		boolean[] order = {false};
		this.sort(new Object[]{"recordDate"}, order);
	}
}
